package net.jwtools.tmt.ui;

import info.clearthought.layout.TableLayout;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import net.jwtools.tmt.service.IVisitService;
import net.jwtools.tmt.service.VisitService;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class SummaryJPanel extends javax.swing.JPanel {
	private JPanel jPanel1;
	private VisitHistoryJPanel visitHistoryJPanel;
	private SummaryPieJPanel summaryPieJPanel;
	private IVisitService visitService;

	/**
	 * Auto-generated main method to display this JPanel inside a new JFrame.
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] {
						"/net/jwtools/tmt/ctx/tmt-application-context.xml",
						"/net/jwtools/tmt/ctx/tmt-data-access-context.xml" });

		BeanFactory factory = (BeanFactory) context;

		frame.getContentPane().add(
				new SummaryJPanel((VisitService) factory
						.getBean("visitService")));
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}

	public SummaryJPanel(IVisitService visitService) {
		super();
		this.visitService = visitService;
		initGUI();
	}

	private void initGUI() {
		try {
			BorderLayout thisLayout = new BorderLayout();
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(1000, 700));
			{
				jPanel1 = new JPanel();
				this.add(jPanel1, BorderLayout.CENTER);
				TableLayout jPanel1Layout = new TableLayout(new double[][] {
						{ TableLayout.FILL, TableLayout.FILL, TableLayout.FILL,
								TableLayout.FILL },
						{ TableLayout.FILL, TableLayout.FILL, TableLayout.FILL,
								TableLayout.FILL, TableLayout.FILL,
								TableLayout.FILL } });
				jPanel1Layout.setHGap(5);
				jPanel1Layout.setVGap(5);
				jPanel1.setLayout(jPanel1Layout);
				{
					summaryPieJPanel = new SummaryPieJPanel(visitService);
					jPanel1.add(getVisitHistoryJPanel().getControl(),
							"0, 3, 1, 5");
					jPanel1.add(summaryPieJPanel.getControl(), "0, 0, 1, 2");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public SummaryPieJPanel getSummaryPieJPanel() {
		return summaryPieJPanel;
	}

	public IVisitService getVisitService() {
		return visitService;
	}

	public void setVisitService(IVisitService visitService) {
		this.visitService = visitService;
	}

	private VisitHistoryJPanel getVisitHistoryJPanel() {
		if (visitHistoryJPanel == null) {
			visitHistoryJPanel = new VisitHistoryJPanel(getVisitService());
			visitHistoryJPanel
					.setPreferredSize(new java.awt.Dimension(359, 328));
		}
		return visitHistoryJPanel;
	}

}
